package com.dxtx.activity;

import java.util.List;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.dxtx.widget.DragAdapter;


public class MyAdapter extends DragAdapter {

	private Context context;
	private List<String> list;

	public MyAdapter(Context context, List<String> list) {
		this.context = context;
		this.list = list;
	}

	@Override
	public void onDataModelMove(int from, int to) {
		String s = list.remove(from);
		list.add(to, s);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public String getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TextView textView;
		if (convertView == null) {
			FrameLayout frameLayout = new FrameLayout(context);
			convertView = frameLayout;
			textView = new TextView(context);
			frameLayout.setPadding(20, 20, 20, 20);
			textView.setPadding(20, 100, 20, 100);
			frameLayout.addView(textView);
			textView.setBackgroundColor(0x33ff00ff);
			textView.setGravity(Gravity.CENTER);
		} else {
			textView = (TextView) ((FrameLayout) convertView).getChildAt(0);
		}
		textView.setText(getItem(position));
		return convertView;
	}
}
